package com.lmf.eduservice.controller;


import com.lmf.eduservice.entity.subject.OneSubject;
import com.lmf.eduservice.service.EduSubjectService;
import com.lmf.handler.Exception.LmfException;
import com.lmf.resultCode.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author lmf
 * @since 2022-01-22
 */
@RestController
@RequestMapping("/eduservice/edu-subject")
@CrossOrigin
@Api(description="课程分类管理")
public class EduSubjectController {

    @Autowired
    private EduSubjectService eduSubjectService;

//    @SneakyThrows   //自动捕获异常
    @ApiOperation("添加课程，并进行分类")
    @PostMapping("/addSubject")
    public R addSubject(MultipartFile file) throws LmfException {//通过上传文件，将文件内容读取出来
        eduSubjectService.saveSubject(file,eduSubjectService);
        return R.ok().message("添加课程成功！");
    }

    @ApiOperation("获取所有分类课程")
    @GetMapping("/getAllSubject")
    public R getAllSubject(){
        //查询返回所有的一级分类科目，里面包含二级分类科目
        List<OneSubject> list = eduSubjectService.getAllOneTwoSubject();
        return R.ok().data("list",list);
    }
}

